package cn.imvc.app.models;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tencent.xinge.Message;
import com.tencent.xinge.MessageIOS;
import com.tencent.xinge.Style;
import com.tencent.xinge.TimeInterval;
import com.tencent.xinge.XingeApp;

import cn.imvc.app.entities.PushMessage;
import cn.imvc.util.XingeAppUtil;
@Service
public class XingeAppModelImpl implements XingeAppModel {
	
	@Autowired
	XingeAppUtil xingeAppUtil;

	public String pushMessage(String title,String content,String url) {
		TimeInterval acceptTime1 = new TimeInterval(8,0,23,0);
		Map<String, Object> custom = new HashMap<String, Object>();
		custom.put("url", url);
		XingeApp xinge_android = new XingeApp(Long.valueOf(xingeAppUtil.getAndroidAccessId()), xingeAppUtil.getAndroidSecretKey());
		
		Message messageAndroid = new Message();
		messageAndroid.setType(Message.TYPE_NOTIFICATION);
		Style style = new Style(1);
		style = new Style(3,1,0,1,0);
		
		messageAndroid.setTitle(title);
		messageAndroid.setContent(content);
		messageAndroid.setStyle(style);
		messageAndroid.setCustom(custom);
		messageAndroid.addAcceptTime(acceptTime1);
		
		JSONObject ret = xinge_android.pushAllDevice(0, messageAndroid);
		System.out.println(ret);
		
		
		XingeApp xinge_ios = new XingeApp(Long.valueOf(xingeAppUtil.getIosAccessId()), xingeAppUtil.getIosSecretKey());
		MessageIOS messageIos = new MessageIOS();
		messageIos.setExpireTime(86400);
		messageIos.setAlert(content);
		messageIos.setBadge(1);
		messageIos.setSound("beep.wav");
		messageIos.addAcceptTime(acceptTime1);
		messageIos.setCustom(custom);
		ret = xinge_ios.pushAllDevice(0, messageIos,XingeApp.IOSENV_PROD);
		System.out.println(ret);
		return null;
	}

}
